<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@taglib uri="http://www.springframework.org/tags/form" prefix="form" %>
<%@taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<html>
<head></head>
<body>
<c:if test="${not empty msg}">
    <p class="error">${msg}</p>
</c:if>
<h4>You have ${count}
    <c:if test="${type eq 'sent'}">sent</c:if><c:if test="${type eq null}">recieved</c:if> messages</h4>
<c:forEach begin="1" end="${pagecount}" var="i">
    <c:if test="${!(currentpage eq i)}"><a
            href="/voteup/messages/messagespage${i}<c:if test="${type eq 'sent'}">?type=sent</c:if>">${i}</a></c:if>
    <c:if test="${currentpage eq i}">${i}</c:if>
</c:forEach>

<ul class="pane-list">
    <c:forEach items="${messages}" var="message">
        <c:if test="${message.read}"><li class="nocursorhigh"></c:if>
        <c:if test="${not message.read}"><li class="unreadhigh"></c:if>
        <table class="msgtable" align="center">
            <tr>
                <td width="30%" align="left">
                    <c:if test="${type eq null}">
                        <a href="/voteup/persons/${message.fromPerson.personId}">
                            <p align="center"><img src="/voteup/resources/img/avatars/${message.fromPerson.avatar}.jpg"
                                                   width="60"
                                                   height="80"
                                                   border="0"><br>
                                    ${message.fromPerson.lastName} ${message.fromPerson.firstName}</p>
                        </a>
                    </c:if>
                    <c:if test="${type eq 'sent'}">
                        <a href="/voteup/persons/${message.toPerson.personId}">
                            <p align="center"><img src="/voteup/resources/img/avatars/${message.toPerson.avatar}.jpg"
                                                   width="60"
                                                   height="80"
                                                   border="0"><br>
                                    ${message.toPerson.lastName} ${message.toPerson.firstName}</p>
                        </a>
                    </c:if>
                </td>
                <td align="justify">
                    <c:if test="${type eq null}">
                        <a href="/voteup/messages/${message.messageId}"> Title: ${fn:substring(message.title,0,15)}
                            <c:if test="${fn:length(message.title)>15}">...</c:if><br>
                            Message:<br> ${fn:substring(message.body,0,15)}
                            <c:if test="${fn:length(message.body)>15}">...</c:if>
                        </a>
                    </c:if>
                    <c:if test="${type eq 'sent'}">
                        <a href="/voteup/messages/${message.messageId}?type=sent">
                            Title: ${fn:substring(message.title,0,15)}
                            <c:if test="${fn:length(message.title)>15}">...</c:if><br>
                            Message:<br> ${fn:substring(message.body,0,15)}
                            <c:if test="${fn:length(message.body)>15}">...</c:if>
                        </a>
                    </c:if>
                </td>
                <td align="right">
                        ${message.date}<br>
                        ${message.time}<br>
                    <a href="/voteup/messages/${message.messageId}/deletemessage?currentpage=${currentpage}<c:if test="${type eq 'sent'}">&type=${type}</c:if>">Delete
                        message</a>
                </td>
            </tr>
        </table>
        </li>
    </c:forEach>
</ul>
</body>
</html>